// 图片列表
controllers.controller('userPostListCtrl', ['$scope', '$http', '$rootScope', '$modal', '$window', 'Post', 'AlertService',
    function ($scope, $http, $rootScope, $modal, $window, Post, AlertService) {

        $scope.resetCurrentPageName("会员维护");
        $scope.utils = Food.utils;
        $scope.post = {};
        $scope.postList = Post.postList;

        $scope.pageSize = 20;
        $scope.currentPage = 1;
        $scope.totalItems = Post.totalItems;

        $scope.queryList = function () {
            Post.queryList($scope.post, function () {
                $scope.totalItems = Post.totalItems;
            });
        };
        $scope.queryList();

        $scope.pcRegister = function () {
            Post.pcRegister($scope.member, function () {

            });
        };
        $scope.updatePostStatus = function (entity, status) {
            Post.updatePostStatus(entity.publishFileId, status, function () {
                entity.status = status;
            });
        };

        var operateTemplate =
            "<button ng-if='row.entity.status==1 || row.entity.status==2' class='btn btn-primary btn-sm' ng-click='grid.appScope.updatePostStatus(row.entity, 0)'>删除</button>&nbsp;&nbsp;" +
            "<button ng-if='row.entity.status==0' class='btn btn-primary btn-sm' ng-click='grid.appScope.updatePostStatus(row.entity, 1)'>还原</button>&nbsp;&nbsp;" +
            "<button ng-if='row.entity.status==1' class='btn btn-primary btn-sm' ng-click='grid.appScope.updatePostStatus(row.entity, 2)'>置顶</button>&nbsp;&nbsp;" +
            "<button ng-if='row.entity.status==2' class='btn btn-primary btn-sm' ng-click='grid.appScope.updatePostStatus(row.entity, 1)'>取消置顶</button>";

        $scope.gridOptions = {
            data: 'postList',
            enableColumnMenus: false,
            enableColumnResizing: true,
            columnDefs: [
                {
                    field: 'content',
                    displayName: '文章内容'
                }, {
                    field: 'memberName',
                    displayName: '文章创建者'
                }, {
                    field: 'remark',
                    displayName: '备注'
                }, {
                    field: 'approvalCount',
                    displayName: '点赞数'
                }, {
                    field: 'favoriteCount',
                    displayName: '收藏数'
                }, {
                    field: 'commentCount',
                    displayName: '评论数'
                }, {
                    field: 'id',
                    displayName: '操作',
                    width: "20%",
                    cellTemplate: operateTemplate
                }
            ]
        };

    }]);

